package com.itheima.controller;

import com.itheima.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/updatePassword")
    public void updatePassword(HttpServletRequest request){
        Principal principal = request.getUserPrincipal();
        System.out.println(principal.getName());
    }
    @RequestMapping("/getUsername")
    public String getUsername(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            if(user==null){
                return null;
            }else {
                return user.getUsername();
            }
    }
}
